<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <title>title</title>
        <link rel="stylesheet" href="../../css/api.css"/>
        <link rel="stylesheet" href="../../css/common.css" />
        <link rel="stylesheet" href="../../css/query.css"/>
        <link rel="stylesheet" href="../../script/ccssoft/css/ccssoft-lite.css" />
        <link rel="stylesheet" href="../../css/aui.css"/>
        <style>
          #searchHistory p{
            text-align: center;
            padding: 8px 0;
            border-bottom: 1px solid #efefef;
          }

        </style>
    </head>
    <style>
        html, body {
            height: auto;
        }
        body.active {
            background: url(../../image/icons/png/page_icon_empty.png) no-repeat center center;
        }
    </style>
    <body>
      <div id="searchHistory" style="width:100%;background-color:#fff;display:none;">

      </div>
        <div id="main">
            <ul  id="listView" class="ccssoft_list"></ul>
        </div>
        <script id="listView-template" type="text/x-dot-template">
            {{ for(var i=0, len=it.length; i < len; i++) {}}
            <li onclick="stationClick('{{=it[i].hiddencontent != null ? it[i].hiddencontent:""}}','{{=it[i].hiddengrade != null ? it[i].hiddengrade:""}}');" >
            <div class="cj-l-title">{{=it[i].hiddencontent != null ? it[i].hiddencontent:""}}</div>
            <div class="cj-l-level-info">隐患级别:{{=it[i].hiddengrade != null ? it[i].hiddengrade:""}}</div>
            </li>
            {{}}}
        </script>
    </body>
    <script src="../../script/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/debug.js"></script>
    <script type="text/javascript" src="../../script/config.js"></script>
    <script type="text/javascript" src="../../script/doT.min.js"></script>
    <script src="../../script/client.api.js"></script>
    <script type="text/javascript" src="../../script/aui-alert.js"></script>
    <script src="../../script/common.js"></script>
    <script src="../../script/ccssoft/js/ccssoft-lite.js"></script>
    <script type="text/javascript">
        apiready = function() {
            initHeader();
            listView = new C.ApiListView({
                fn : $client.repairInspstand,
                listName : 'systasklist'
            });

            history();
            call_queryKey("",true);
        };
        /**
         *站址点击事件
         */
        function stationClick(hiddencontent, hiddengrade) {
            saveSearchContent(hiddencontent);
            var script = "onDangerSelect('" + hiddencontent + "','" + hiddengrade + "');";
            api.execScript({
                name : 'createRepair',
                frameName : 'createRepairDetail',
                script : script
            });
            api.closeWin();
        }

        /**
         *查询关键字
         */
        function call_queryKey(searchKey,initSearch = false) {
            // if (searchKey == "" && !initSearch) {
            //     $('#listView').empty().removeClass('alert-bg-empty');
            //     return;
            // }
            var opts = {
                hiddencontent : searchKey,
                devname:api.pageParam.devname,
                objtype:api.pageParam.objtype,
                initSearch
            };
            api.showProgress({
                title : '查询中...'
            });
            listView.setQueryOptions(opts);
            listView.refresh();
        }
        // 设置历史查询
        function history(){
          console.log(JSON.stringify(histArr));
          var divHistory = document.getElementById('searchHistory');
          var PHtml='';
          for(var i = 0; i < histArr.length; i++){
            PHtml+="<p onclick='value(this)'>"+histArr[i]+"</p>"
          }
          console.log(PHtml);
          divHistory.innerHTML =PHtml;
        }

        //给搜索框赋值
        function value(e){
          // $('#keyInput').val(searchHis);
          api.execScript({
              name : 'dangerSearch_win',
              script : 'searchVal("' + $(e).html() + '");'
          });
          $('#searchHistory').hide(0);
        }


        //  添加存储定量搜索历史功能
        var histArr;
        var hisDangerStorage=$api.getStorage('hisDangerStorage');
        if(hisDangerStorage){
          histArr=hisDangerStorage;
        }else {
          histArr=[];
        }
        function saveSearchContent(searchKey){

          if(searchKey){

            if(histArr.length>=10){
                histArr.splice(histArr.length-1,1);
            }
            if(histArr.indexOf(searchKey)==-1){
              histArr.unshift(searchKey);
            }
            $api.setStorage('hisDangerStorage', histArr);
          }

        }

        function showSearch(){
          $('#searchHistory').show(0);
        }
        function searchHide(){
          $('#searchHistory').hide(0);
        };
    </script>
</html>
